package com.flyduck.controller;

import com.flyduck.common.lang.Result;
import com.flyduck.service.AuthService;
import com.flyduck.vo.CaptchaCreateRespVO;
import com.flyduck.vo.UserInfoRespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * <p>
 * SysAuthController
 * </p>
 *
 * @author flyduck
 * @since 2024-05-28
 */
@RestController
public class AuthController extends BaseController{

    @Autowired
    private AuthService authService;

    @GetMapping("/captcha")
    public Result<CaptchaCreateRespVO> captcha(){
        CaptchaCreateRespVO captchaCreateRespVO = authService.createCaptcha();
        return Result.success(captchaCreateRespVO);
    }

    @GetMapping("/sys/userInfo")
    public Result<UserInfoRespVO> userInfo(Principal principal){
        UserInfoRespVO userInfoRespVO = authService.getUserInfoByUserName(principal.getName());
        return Result.success(userInfoRespVO);
    }
}
